package com.lhkj.ct.admin.modules.questionnaire.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.questionnaire.model.entity.TblQnrResult;
import com.lhkj.ct.meta.modules.questionnaire.model.vo.QnrStatisticsVo;
import com.lhkj.ct.meta.modules.questionnaire.model.vo.QuestionnaireStatisticsVo;
import com.lhkj.ct.meta.modules.questionnaire.service.QnrAllotRecordService;
import com.lhkj.ct.meta.modules.questionnaire.service.QnrResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author job
 * @since 2023/10/30
 */
@RestController
@RequestMapping("api/plat/qnr/statistics")
@Api(tags = {"5.4问卷统计"})
@Validated
public class QnrStatisticsController {

    @Resource
    private QnrAllotRecordService qnrAllotRecordService;

    @Resource
    private QnrResultService qnrResultService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "列表查询")
    @GetMapping(value = "list")
    public ActionResult<IPage<QnrStatisticsVo>> list(PageQuery pageQuery) {
        return ActionResult.success(qnrAllotRecordService.statistics(pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "答卷收集")
    @GetMapping(value = "{qnrId}/collect")
    public ActionResult<IPage<TblQnrResult>> collect(@PathVariable String qnrId, TblQnrResult result, PageQuery pageQuery) {
        result.setQnrId(qnrId);
        return ActionResult.success(qnrResultService.selectQnrResultPage(result, pageQuery));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "统计分析-查看接口")
    @GetMapping(value = "{qnrId}/statistics")
//    //@RequiresPermissions("XLCY:DCJG:STATISTICS")
    public ActionResult<QuestionnaireStatisticsVo> statistics(@PathVariable String qnrId, PageQuery pageQuery) {
        return ActionResult.success(qnrResultService.statistics(qnrId, pageQuery));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "统计分析-导出", produces = "application/octet-stream")
    @GetMapping(value = "{qnrId}/exportPdf")
//    //@RequiresPermissions("XLCY:DCJG:STATISTICS")
    public void exportPdf(@PathVariable String qnrId, PageQuery pageQuery) {
         qnrResultService.exportStatistics(qnrId, pageQuery);
    }
}
